<title>新增教室</title>
<form class="layui-form" action="" method="post" lay-filter="LAY-classroom-form-add">
    <div class="layui-form-item">
        <label class="layui-form-label">教室编号</label>
        <div class="layui-input-inline">
            <input type="text" name="roomNo" placeholder="请输入教室编号" autocomplete="off" class="layui-input"
                   lay-verify="required|roomNo">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">教室类型</label>
        <div class="layui-input-inline">
            <select name="type">
                <option value="Laboratory">实验室</option>
                <option value="MULTI_MEDIA" selected="">多媒体教室</option>
                <option value="MUSIC_ROOM">音乐教室</option>
                <option value="STYDY_ROOM">自习室</option>
                <option value="MEETING_ROOM">会议室</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">教室地址</label>
        <div class="layui-input-inline">
            <input type="text" name="address" placeholder="请输入教室地址" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-inline">
            <input type="text" name="remark" placeholder="请输入备注信息" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">教室容纳人数</label>
        <div class="layui-input-inline">
            <input type="text" name="capacity" placeholder="请输入教室容纳人数" autocomplete="off" class="layui-input"
                   lay-verify="required|number">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">可用状态</label>
        <div class="layui-input-inline">
            <input type="checkbox" name="status" lay-skin="switch" lay-text="可用|禁用" checked="" value="true">
        </div>
    </div>

    <!--<div class="layui-form-text">
        <div class="layui-inline">
            <label class="layui-form-label">相关图片[637x442]</label>
            <div class="layui-input-inline">
                <div class="layui-upload">
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        <div class="layui-upload-list" id="upload-more-list">
                            <input type="hidden" data-multiple="true" data-maxnum="4" name="imgs" lay-verify="required">
                        </div>
                    </blockquote>
                </div>
            </div>
        </div>
    </div>-->

   <!-- <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">预览图[750x360]</label>
            <div class="layui-input-inline">
                <div class="layui-upload">
                    <input type="hidden" name="imgUrl">
                </div>
            </div>
        </div>
    </div>-->


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="LAY-classroom-save">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>


</form>
<script>
    layui.use(['admin', 'form'], function () {
        var $ = layui.$
            , admin = layui.admin
            , setter = layui.setter
            , layer = layui.layer
            , response = setter.response
            , form = layui.form;

        form.render(null, 'LAY-classroom-form-add');

       /* $('[name=imgUrl]').xwbzImg({
            width: '208px',
            height: '100px',
            url: '/common/file/upload_multi',
            error: function (err) {
                layer.msg(err, {
                    icon: 2
                });
            }
        });*/
        //自定义验证规则
        form.verify({
            roomNo: function (value) {
                var reg = /^[0-9a-z_A-Z]+$/;
                if (!reg.test(value)) {
                    return '教室编号只能由字母或者数字组成';
                }
                if (value.length < 5) {
                    return '教室编号最少5个字符';
                }
                if (value.length > 20) {
                    return '教室编号最多20个字符';
                }
            }
        });
        form.on('submit(LAY-classroom-save)', function (data) {
           /* // 上传图片校验
            if(!data.field.imgs) {
                layer.msg('请上传相关图片', {
                    icon: 2
                });
                return false
            } else {
                data.field.imgs = data.field.imgs.split(',');
            }
*/
            admin.req({
                url: '/admin/classroom'
                , type: 'POST'
                , data: data.field
                , success: function (res) {
                    var statusCode = response.statusCode;
                    if (res[response.statusName] === statusCode.ok) {
                        layer.closeAll('page');  //关闭page的弹框
                        layer.msg('新增教室成功', {
                            icon: 1
                        });
                    }
                }
            });
            return false;
        });
    });
    layui.data.done = function (d) {
        layui.use(['form'], function () {
            var form = layui.form;
            form.render(null, 'LAY-classroom-form-add'); //渲染该模板下的动态表单
        });
    };
</script>
